﻿package plugin.chatflash.component
{
    import cmd.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;

    public class BugleText extends Sprite
    {
        private var mMask:Sprite;
        private var mText:TextField;
        private var mShowing:Boolean = false;
        protected var mFilter:DropShadowFilter;

        public function BugleText()
        {
            this.mFilter = new DropShadowFilter(0, 0, 0, 0.8, 2, 2, 10, 1);
            this.createChildren();
            this.visible = false;
            return;
        }// end function

        private function createChildren() : void
        {
            this.mMask = new Sprite();
            this.mMask.graphics.beginFill(16777215);
            this.mMask.graphics.drawRect(64, 0, 274, 26);
            this.mMask.graphics.endFill();
            addChild(this.mMask);
            return;
        }// end function

        public function showBugle(param1:String) : void
        {
            if (this.mShowing)
            {
                return;
            }
            this.mShowing = true;
            this.createText();
            this.mText.htmlText = param1;
            this.mText.x = 338;
            this.mText.y = 5;
            this.visible = true;
            addEventListener(Event.ENTER_FRAME, this.enterFrameHandler);
            return;
        }// end function

        private function enterFrameHandler(event:Event) : void
        {
            (this.mText.x - 1);
            if (this.mText.x < -this.mText.textWidth + 64)
            {
                this.mShowing = false;
                this.visible = false;
                this.clearText();
                removeEventListener(Event.ENTER_FRAME, this.enterFrameHandler);
                if (hasEventListener(Event.COMPLETE))
                {
                    dispatchEvent(new Event(Event.COMPLETE));
                }
            }
            return;
        }// end function

        private function createText() : void
        {
            this.mText = new TextField();
            this.mText.autoSize = TextFieldAutoSize.LEFT;
            this.mText.textColor = UIGlobel.chanel2color(ChatCMD.ChannelSpecial);
            this.mText.filters = [this.mFilter];
            addChild(this.mText);
            this.mText.mask = this.mMask;
            return;
        }// end function

        private function clearText() : void
        {
            if (this.mText)
            {
                if (this.mText.parent)
                {
                    this.mText.parent.removeChild(this.mText);
                }
                this.mText = null;
            }
            return;
        }// end function

        public function get showing() : Boolean
        {
            return this.mShowing;
        }// end function

    }
}
